import axios from "../request/service.js";
import {get,post} from '../request/service.js'

export function login(username,password,type){
    return axios.post("/login",{
        username,
        password,
        type
    })
}

export const loginApi=data=>{
    return post({
        url:'/login',
        data
    })
}

export const exitApi = () => {
    return post({
        url:'/logout'
    })
}

/* 医生模块 */
export function getDoctorInfo(){
    return get({
        url:'/doc/getInfo'
    })
}

export function getDocSignInfo(){
    return get({
        url:'/doc/browse'
    })
}

export function getCusInfo(id){
    return get({
        url:'/doc/customerview/'+id
    })
}

export function geneQRCode(){
    return get({
        url:'/qrcode/gene'
    })
}

export function changePsw(data){
    return axios.put('/doc/updatemes',data)
}

export function closeCnt(name){
    return axios.post('/doc/endInquiry/'+name)
}

export function saveDocInfo(data){
    return axios.post('/doc/updateInfo',data)
}

//New--获取用户伤病记录
export function getillness(cId){
    return get({
        url:'/doc/getillness/'+cId
    })
}

//New--增加用户伤病记录
export const addillness=(cusId)=>{
    return axios.post('/doc/addOrSaveIllness',cusId)
}

//New--删除用户伤病记录
export function delillness(treatId){
    return axios.delete('/doc/del/'+treatId)
}

//就诊预约
export function getDocVisitInfo(data){
    return get({url:'/doc/checkorder',params:{cusName:data}})
}

//接收就诊预约
export function acceptReqId(id){
    return axios.post('/doc/accept/'+ id)
}

//转诊就诊预约
export function transferReqId(ReqId,docId){
    return axios.post('/doc/transfer/'+ ReqId+'/'+docId)
}

/* 消息接口 */
export function getMessage(){
    return get({
        url:'/msg/getMessage'
    })
}

export function changeMsgState(action,msgIds){
    return axios.post('/msg/updateMessage',{
            action,
            msgIds  
    })
}

export function delMsg(msgIds){
    return axios.delete('/msg/delMessage',{params:{msgIds:msgIds}})
}

export function getMsgNum(){
    return axios.get('/msg/countMsg')
}

/* */
export function getAcceptedInfo(){
    return get({
        url:'/doc/getApp'
    })
}

/* 用户模块 */


//查看所有医生信息
export function getAlldoctorInfo(){
    return get({
        url:'/cus/getAllDoctor'
    })
}

//查看签约医生信息
export function getCusdoctorInfo(){
    return get({
        url:'/cus/doctorview'
    })
}

export function getUserInfo(){
    return get({
        url:'/cus/customerview'
    })
}

//用户就诊预约
export const userappVisit=(data)=>{
    return post({
        url:'/cus/appVisit',
        data
    })
}

export function getdoctorDetail(id){
    return get({
     url:'/cus/getDoctorDetail/'+id
    })
}

//保存信息
export function saveUserInfo(data){
    return axios.post('/cus/updateInfo',data)
}

/* 管理员模块 */
// export function getAdmDocInfo(){
//     return get({url:'/admin/getDocs'})
// }
export function getAdmDocInfo(data){
    return get({url:'/admin/getDocs',params:{docName:data}})
}


export const addAdmDocInfo=data=>{
    return post({
        url:'/admin/addDoc',
        data
    })
}

export function changeCusPsw(data){
    return axios.put('/cus/updatemes',data)
}

export const changeAdmPsw=data=>{
    return post({
        url:'/admin/updatepswd',
        data
    })
}

export function deldoctor(id){
    return axios.delete('/admin/delDoc/'+id)
}

/* 管理员模块--Cus */
export function getAdmCusInfo(){
    return get({url:'/admin/getCus'})
}

export const addAdmCusInfo=data=>{
    return post({
        url:'/admin/addCus',
        data
    })
}

export function delcustomer(id){
    return axios.delete('/admin/delCus/'+id)
}

export function getBookedDoc(){
    return get({
        url:'/cus/getApp'
    })
}
/* 上传头像 */
export function uploadImg(img){
    const formData = { 'img' : img }
    //formData.append('img', img)
    let config = {
        headers:{'Content-Type':'multipart/form-data'}
    }
    return axios.post('/upload',formData,config)
}